/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.*;
import vical.action.*;
import vical.model.Internationalization;
import vical.view.ViewPanel.ViewType;
import java.awt.event.KeyEvent;

/**
 * The navigationBar is used to switch among views, navigate in a calendar.
 * also with some necessary captions.
 * 
 * @author Can
 * @author Pooya
 * @author Flora
 */
public class NavigationBar extends JPanel {

    private ViewPanel viewPanel;
    // navigation
    private JButton todayButton;
    private JButton nextButton;
    private JButton previousButton;
    // buttons to change views
    private JToggleButton monthViewButton;
    private JToggleButton weekViewButton;
    private JToggleButton dayViewButton;
    private JToggleButton listViewButton;
    private JLabel captionLabel;
    private JPanel navigationLeftSegment;
    private JPanel navigationRightSegment;
    private JPanel navigationMiddleSegment;

    private NavigationBar() {
    }

    public NavigationBar(ViewPanel viewPanel) {
        this.viewPanel = viewPanel;
        initComponents();
    }

    private void initComponents() {
        navigationLeftSegment = new JPanel();
        navigationRightSegment = new JPanel();
        navigationMiddleSegment = new JPanel();

//        navigationRightSegment.setSize(200, WIDTH);

        todayButton = new JButton(new ViewTodayAction(viewPanel));
        todayButton.putClientProperty("JButton.buttonType", "segmented");
        todayButton.putClientProperty("JButton.segmentPosition", "only");
        todayButton.putClientProperty("JComponent.sizeVariant", "regular");
        todayButton.setPreferredSize(new Dimension(80, 20));
        todayButton.setFocusable(false);
       
        todayButton.setToolTipText(Internationalization.getString("tooltip_today_button"));


        previousButton = new JButton(new ViewPreviousAction(viewPanel));
        previousButton.putClientProperty("JButton.buttonType", "segmented");
        previousButton.putClientProperty("JButton.segmentPosition", "first");
        previousButton.putClientProperty("JComponent.sizeVariant", "regular");
        previousButton.setPreferredSize(new Dimension(45, 20));
        previousButton.setFocusable(false);
        previousButton.setToolTipText(Internationalization.getString("tooltip_previous_arrow_button"));

        nextButton = new JButton(new ViewNextAction(viewPanel));
        nextButton.putClientProperty("JButton.buttonType", "segmented");
        nextButton.putClientProperty("JButton.segmentPosition", "last");
        nextButton.putClientProperty("JComponent.sizeVariant", "regular");
        nextButton.setPreferredSize(new Dimension(45, 20));
        nextButton.setFocusable(false);
        nextButton.setToolTipText(Internationalization.getString("tooltip_next_arrow_button"));

        captionLabel = new JLabel();
        captionLabel.setForeground(Color.WHITE);
        captionLabel.setFont(new Font("sansserif", Font.BOLD, 15));

        monthViewButton = new JToggleButton(new MonthViewAction(viewPanel));
        monthViewButton.putClientProperty("JButton.buttonType", "segmented");
        monthViewButton.putClientProperty("JButton.segmentPosition", "middle");
        monthViewButton.putClientProperty("JComponent.sizeVariant", "regular");
        monthViewButton.setPreferredSize(new Dimension(75, 20));
        monthViewButton.setFocusable(false);
        monthViewButton.setToolTipText(Internationalization.getString("tooltip_month_view_button"));

        weekViewButton = new JToggleButton(new WeekViewAction(viewPanel));
        weekViewButton.putClientProperty("JButton.buttonType", "segmented");
        weekViewButton.putClientProperty("JButton.segmentPosition", "middle");
        weekViewButton.putClientProperty("JComponent.sizeVariant", "regular");
        weekViewButton.setPreferredSize(new Dimension(75, 20));
        weekViewButton.setFocusable(false);
        weekViewButton.setToolTipText(Internationalization.getString("tooltip_7_days_view_button"));

        dayViewButton = new JToggleButton(new DayViewAction(viewPanel));
        dayViewButton.putClientProperty("JButton.buttonType", "segmented");
        dayViewButton.putClientProperty("JButton.segmentPosition", "middle");
        dayViewButton.putClientProperty("JComponent.sizeVariant", "regular");
        dayViewButton.setPreferredSize(new Dimension(75, 20));
        dayViewButton.setFocusable(false);
        dayViewButton.setToolTipText(Internationalization.getString("tooltip_day_view_button"));

        listViewButton = new JToggleButton(new ListViewAction(viewPanel));
        listViewButton.putClientProperty("JButton.buttonType", "segmented");
        listViewButton.putClientProperty("JButton.segmentPosition", "middle");
        listViewButton.putClientProperty("JComponent.sizeVariant", "regular");
        listViewButton.setPreferredSize(new Dimension(75, 20));
        listViewButton.setFocusable(false);
        listViewButton.setToolTipText(Internationalization.getString("tooltip_list_view_button"));

        // Layout
        this.setLayout(new BorderLayout());

        navigationLeftSegment.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 8));
        navigationLeftSegment.add(Box.createRigidArea(new Dimension(4, 0)));
        navigationLeftSegment.add(todayButton);
//        navigationLeftSegment.setPreferredSize(new Dimension(130, 32));

        navigationMiddleSegment.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 8));
//        navigationMiddleSegment.setPreferredSize(new Dimension(400, 32));
        navigationMiddleSegment.add(previousButton);
        navigationMiddleSegment.add(monthViewButton);
        navigationMiddleSegment.add(weekViewButton);
        navigationMiddleSegment.add(dayViewButton);
        navigationMiddleSegment.add(listViewButton);
        navigationMiddleSegment.add(nextButton);
        navigationMiddleSegment.add(Box.createRigidArea(new Dimension(4, 0)));

        navigationRightSegment.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 8));
        navigationRightSegment.add(captionLabel);
//        navigationRightSegment.setPreferredSize(new Dimension(270, 32));
//      new Color(226, 37, 117)
        navigationMiddleSegment.setBackground(Color.ORANGE);
        navigationLeftSegment.setBackground(Color.ORANGE);
        navigationRightSegment.setBackground(Color.ORANGE);

        this.add(BorderLayout.CENTER, navigationRightSegment);
        this.add(BorderLayout.WEST, navigationLeftSegment);
        this.add(BorderLayout.EAST, navigationMiddleSegment);
    }

    public void setCaption(String text) {
        captionLabel.setText(text);
    }

    public void setButtonPressed(ViewType type) {
        monthViewButton.setSelected(false);
        weekViewButton.setSelected(false);
        dayViewButton.setSelected(false);
        listViewButton.setSelected(false);
        if (type == ViewType.MonthView) {
            monthViewButton.setSelected(true);
        } else if (type == ViewType.WeekView) {
            weekViewButton.setSelected(true);
        } else if (type == ViewType.DayView) {
            dayViewButton.setSelected(true);
        } else if (type == ViewType.ListView) {
            listViewButton.setSelected(true);
        }
    }
}
